#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 7;
int n, m;
char a[N], b[N];
int dp[N][N];
int main() {
  memset(dp, 0x3f, sizeof dp);
  cin >> n >> a + 1 >> m >> b + 1;
  for (int i = 0; i <= N; ++i) dp[i][0] = dp[0][i] = i;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (a[i] == b[j])
        dp[i][j] = min(dp[i][j], dp[i - 1][j - 1]);
      else
        dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1);
      dp[i][j] = min({dp[i][j], dp[i - 1][j] + 1, dp[i][j - 1] + 1});
    }
  }
  cout << dp[n][m] << endl;
}
